package bean.dao;

import java.util.List;
import java.util.Set;

import hbt.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import bean.Cliente;
import bean.Telefono;

public class HibertnateNegocioDAO {
	private static HibertnateNegocioDAO instancia = null;
	private static SessionFactory sf = null;
	
	public static HibertnateNegocioDAO getInstance(){
		if (instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibertnateNegocioDAO();
		}
		return instancia;
	}
	
	public void grabarCliente(Cliente cli){
		Session sesion = sf.openSession();
		sesion.beginTransaction();
		sesion.persist(cli);
		sesion.flush();
		sesion.getTransaction().commit();
		sesion.close();
		
		
	}

	public void grabarTelefono(Telefono tel) {
		// TODO Auto-generated method stub
		Session sesion = sf.openSession();
		sesion.beginTransaction();
		sesion.persist(tel);
//		sesion.flush();
		sesion.getTransaction().commit();
		sesion.close();
		
	}

	public List<Cliente> obtenerClientes() {
		// TODO Auto-generated method stub
		Session session = sf.openSession();
		List<Cliente> list =  session.createQuery("from Cliente").list();
		return list;
	}

}
